package com.zhiche.lisa.bms.service.statistics.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.google.common.collect.Maps;
import com.zhiche.lisa.bms.dao.mapper.statistics.StaticBillDetailMapper;
import com.zhiche.lisa.bms.dao.model.statistics.StaticBillDetail;
import com.zhiche.lisa.bms.pojo.bo.statistics.BillDetailBO;
import com.zhiche.lisa.bms.service.statistics.StaticBillDetailService;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 账单明细统计表 服务实现类
 * </p>
 *
 * @author liangpeng
 * @since 2019-01-18
 */
@Service
public class StaticBillDetailServiceImpl extends ServiceImpl<StaticBillDetailMapper, StaticBillDetail> implements StaticBillDetailService {

    /**
     * 得到应收账单明细统计表
     *
     * @param intCount
     * @return
     */
    @Override
    public List<BillDetailBO> getARBillDetailBO(int intCount) {
        EntityWrapper<BillDetailBO> ew = new EntityWrapper<>();
        ew.orderBy("gmt_modify");
        if(intCount >0 ){
            ew.last("limit " + intCount);
        }
        return baseMapper.getARBillDetailBO(ew);
    }

    /**
     * 算总金额
     *
     * @return
     */
    @Override
    public Map<String, BigDecimal> getBillDetailInvoiceMoney() {
        List<BillDetailBO> billDetailInvoiceMoney = baseMapper.getBillDetailInvoiceMoney();
        Map<String, BigDecimal> resultMap = Maps.newHashMap();
        if (CollectionUtils.isNotEmpty(billDetailInvoiceMoney)) {
            billDetailInvoiceMoney.forEach(dtl -> {
                resultMap.put(dtl.getSysOrderId(), dtl.getInvoiceMoney());
            });
        }
        return resultMap;
    }

    /**
     * 得到应付账单明细统计表
     *
     * @param intCount
     * @return
     */
    @Override
    public List<BillDetailBO> getAPBillDetailBO(int intCount) {
        EntityWrapper<BillDetailBO> ew = new EntityWrapper<>();
        ew.orderBy("gmt_modify");
        if(intCount >0 ){
            ew.last("limit " + intCount);
        }
        return baseMapper.getAPBillDetailBO(ew);
    }
}
